﻿/**
 * Discription: 
 * File Name:   $ItemName$.cs
 * Author   :   陈小磊(Gtalk/Email:chenlei@hzexe.com)
 * Create Time: 2013/12/16 10:21:37
 * CLR Version: 4.0.30319.18052
 * File Identification: 8b0f782f-05d3-417f-a1bc-b527a0724727
 * Create by wpc\machinename in project named "$ProjectName$" 
 * =================================================
 * Modify Records
 *          
 * 
 * 
 * 
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;

namespace Hzexe.Wechat.SharpSDK.Message.Push
{
    /// <summary>
    /// 客服消息对象
    /// </summary>
    /// <typeparam name="T">消息类型</typeparam>
    [MyJsonProperty]
    public class PushMessage<T> where T : Msg,new()
    {
        /// <summary>
        /// 实例化一个客服消息
        /// </summary>
        public PushMessage()
        {
            data = new T();
            this.msgtype = data.msgtype;
        }

        /// <summary>
        /// 调用接口凭证 
        /// </summary>
        public string access_token { get; set; }

        /// <summary>
        /// 接收者
        /// </summary>
        /// <remarks>普通用户openid </remarks>
        public string touser { get; set; }

        /// <summary>
        /// 消息类型
        /// </summary>
        [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
        public EnumPushType msgtype { get; set; }

        /// <summary>
        /// 有效何载,比如是文本类型消息还是图像类型消息
        /// </summary>
        public T data { get; set; }

        /// <summary>
        /// 获取json对象,已重写
        /// </summary>
        /// <returns>json序列化的结果</returns>
        public override string ToString()
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(this,
                Newtonsoft.Json.Formatting.Indented,
                new JsonConverter[]{new PushMsgConverter()});
        }





    }

    /// <summary>
    /// 消息类型
    /// </summary>
    public enum EnumPushType
    {
        /// <summary>
        /// 文本消息
        /// </summary>
        text,
        /// <summary>
        /// 图片消息
        /// </summary>
        image,
        /// <summary>
        /// 语音消息
        /// </summary>
        voice,
        /// <summary>
        /// 视频消息
        /// </summary>
        video,
        /// <summary>
        /// 音乐消息
        /// </summary>
        music,
        /// <summary>
        /// 图文消息
        /// </summary>
        news
    }

    /// <summary>
    /// 需要自定义序列化的属性
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class MyJsonProperty :System.Attribute
    { 
        
    }


}
